package com.jckl.foodathon.model;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Index;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.beoui.geocell.annotations.Geocells;
import com.beoui.geocell.annotations.Latitude;
import com.beoui.geocell.annotations.Longitude;
import com.google.appengine.api.datastore.Blob;
import com.google.appengine.api.datastore.GeoPt;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.datanucleus.annotations.Unowned;

@PersistenceCapable(detachable = "true")
public class Store {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	@Persistent
	@Index(name = "STORENAME", unique = "true")
	private String name;

	@Persistent
	private String address_unitNumber;
	@Persistent
	private String address_buildingName;
	@Persistent
	private String address_streetName;
	@Persistent
	private String address_area;
	@Persistent
	private String address_postcode;
	@Persistent
	private String address_state;
	@Persistent
	private String address_country;

	@Persistent
	@Longitude
	private double longitude;
	@Persistent
	@Latitude
	private double latitude;
	@Persistent
	private GeoPt point;
	@Persistent
	@Geocells
	private List<String> geoCells;

	@Persistent
	private String contactNo;
	@Persistent
	private String contactPerson;
	@Persistent
	private String notes;
	private String encodedImage;
	@Persistent
	private Blob image;
	@Persistent
	private String website;
	@Persistent
	private String email;

	// Data Relationship
	@Persistent
	@Unowned
	private StoreType storeType;
	@Persistent
	@Unowned
	private Set<Blog> blogs;
	@Persistent
	@Unowned
	private Brand brand;
	@Persistent
	@Unowned
	private Set<StoreTag> storeTags;

	// Data Related Info
	@Persistent
	private Date createdDate;
	@Persistent
	private Date updatedDate;
	@Persistent
	private boolean active;
	
	/**
	 * Getter & Setter
	 */

	public Key getKey() {
		return key;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress_unitNumber() {
		return address_unitNumber;
	}

	public void setAddress_unitNumber(String address_unitNumber) {
		this.address_unitNumber = address_unitNumber;
	}

	public String getAddress_buildingName() {
		return address_buildingName;
	}

	public void setAddress_buildingName(String address_buildingName) {
		this.address_buildingName = address_buildingName;
	}

	public String getAddress_streetName() {
		return address_streetName;
	}

	public void setAddress_streetName(String address_streetName) {
		this.address_streetName = address_streetName;
	}

	public String getAddress_area() {
		return address_area;
	}

	public void setAddress_area(String address_area) {
		this.address_area = address_area;
	}

	public String getAddress_postcode() {
		return address_postcode;
	}

	public void setAddress_postcode(String address_postcode) {
		this.address_postcode = address_postcode;
	}

	public String getAddress_state() {
		return address_state;
	}

	public void setAddress_state(String address_state) {
		this.address_state = address_state;
	}

	public String getAddress_country() {
		return address_country;
	}

	public void setAddress_country(String address_country) {
		this.address_country = address_country;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public GeoPt getPoint() {
		return point;
	}

	public void setPoint(GeoPt point) {
		this.point = point;
	}

	public String getContactNo() {
		return contactNo;
	}

	public void setContactNo(String contactNo) {
		this.contactNo = contactNo;
	}

	public String getContactPerson() {
		return contactPerson;
	}

	public void setContactPerson(String contactPerson) {
		this.contactPerson = contactPerson;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public Blob getImage() {
		return image;
	}

	public void setImage(Blob image) {
		this.image = image;
	}

	public String getWebsite() {
		return website;
	}

	public void setWebsite(String website) {
		this.website = website;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public List<String> getGeoCells() {
		return geoCells;
	}

	public void setGeoCells(List<String> geoCells) {
		this.geoCells = geoCells;
	}

	public Set<Blog> getBlogs() {
		return blogs;
	}

	public void setBlogs(Set<Blog> blogs) {
		this.blogs = blogs;
	}
	
	public void addBlog(Blog blog){
		Set<Blog> blogs = this.blogs;
		
		if (blogs == null){
			blogs = new HashSet<Blog>();
		}
		blogs.add(blog);
		this.blogs = blogs;
	}

	public Brand getBrand() {
		return brand;
	}

	public void setBrand(Brand brand) {
		this.brand = brand;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public Date getUpdatedDate() {
		return updatedDate;
	}

	public void setUpdatedDate(Date updatedDate) {
		this.updatedDate = updatedDate;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public StoreType getStoreType() {
		return storeType;
	}

	public void setStoreType(StoreType storeType) {
		this.storeType = storeType;
	}

	public Set<StoreTag> getStoreTags() {
		return storeTags;
	}

	public void setStoreTags(Set<StoreTag> storeTags) {
		this.storeTags = storeTags;
	}

	public String getEncodedImage() {
		return encodedImage;
	}

	public void setEncodedImage(String encodedImage) {
		this.encodedImage = encodedImage;
	}

}
